package com.zx.test.listener;

import com.google.common.collect.Lists;
import com.zx.flow.api.dict.FlowDict.OperatorRule;
import com.zx.flow.api.listener.FlowCallbackHandler;
import com.zx.flow.api.listener.FlowEvent;
import com.zx.flow.api.listener.FlowEventRegister;
import com.zx.flow.api.listener.request.FlowOperator4Listener;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class QingJiaFlowEventListener implements FlowCallbackHandler {

    public QingJiaFlowEventListener() {
        FlowEventRegister.register("qingjia", this);
    }

    @Override
    public void doListener(FlowEvent flowEvent) {
        log.info("############## 处理事件 begin ##############");
        log.info("flowCode={}, event={}", flowEvent.getFlowContext().getFlowConfigCode(), flowEvent.getEventCode());
        log.info("############## 处理事件 end   ##############");
    }

    @Override
    public List<FlowOperator4Listener> getOperators(FlowEvent flowEvent) {
        log.info("############## 获得操作人 ##############");
        log.info("flowCode={}, event={}", flowEvent.getFlowContext().getFlowConfigCode(), flowEvent.getEventCode());
        return Lists.newArrayList(
                new FlowOperator4Listener("zhangsan", "张三", OperatorRule.operator.getCode()),
                new FlowOperator4Listener("lisi", "李四", OperatorRule.operator.getCode()));
    }
}
